<?php

	include("common.php");
	
	if(!empty($_POST)){
		mysql_query("INSERT INTO `197_articles` ( `title`, `content`, `author`, `post_date` ) VALUES ( '" . $_POST['title'] . "', '" . $_POST['content'] . "', '" . $_POST['author'] . "' , '" . date("Y-m-d") . "' )");
		include("header.php");
?>
<?php if(!AJAX){ ?><h1>新增作文</h1><?php } ?>
<p>新增成功<?php if(!AJAX){ ?>，請<a href="articleFind.php">按此</a>返回<?php } ?>。</p>
<?php

		include("sidebar.php");
		include("footer.php");
		
		exit;

	}
	
?>
<?php include("header.php"); ?>
<h1>新增作文</h1>
<div id="add-result-dialog">
</div>
<script type="text/javascript" defer="defer">
	$("#add-result-dialog").dialog({
		width: 300,
		height: 210,
		autoOpen: false,
		title: "新增作文",
		modal: true,
		draggable: false,
		resizable: false
	});
	function addArticle(){
		$("#add-result-dialog").dialog("option", "buttons", { "關閉": function(){ location.replace("articleFind.php"); } });
		$("#add-result-dialog").html("<img src='../images/ajax-loader.gif' />");
		$("#add-result-dialog").dialog("open");
		$.post("articleAdd.php?ajax=true", { author: $("#author").val(), title: $("#title").val(), content: $("#content").val() }, function(r){ $("#add-result-dialog").html(r) });
	}
</script>
<script type="text/javascript">
	$(function(){
		$('textarea.tinymce').tinymce({
			// Location of TinyMCE script
			script_url : '../jquery/tiny_mce/tiny_mce.js',

			// General options
			theme : "advanced",
			skin : "o2k7",
			plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",

			// Theme options
			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect",
			theme_advanced_buttons2 : "cut,copy,paste,|,search,replace,|,bullist,numlist,|,blockquote,|,undo,redo,|,link,unlink,image,code,styleprops,forecolor,backcolor",
			theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,charmap,emotions,iespell,media,|,print,|,fullscreen",
			theme_advanced_buttons4 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : true,

			// Drop lists for link/image/media/template dialogs
			template_external_list_url : "lists/template_list.js",
			external_link_list_url : "lists/link_list.js",
			external_image_list_url : "lists/image_list.js",
			media_external_list_url : "lists/media_list.js",
		});
	});
</script>
<form action="articleAdd.php" onsubmit="addArticle(); return false;" method="POST">
	<p><label>標題：<input type="text" name="title" id="title" /></label></p>
	<textarea class="tinymce" name="content" id="content"></textarea>
	<p><label>作者：<input type="text" name="author" id="author" /></label></p>
	<p><input type="submit" value="新增" />｜<a href="articleFind.php">返回</a></p>
</form>
<?php include("sidebar.php"); ?>
<?php include("footer.php"); ?>